<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <base href="#(baseUrl)">
    <title>欢迎使用#(appName)</title>
    <link rel="stylesheet" type="text/css" href="static/admin/css/login.css"/>
    <script type="text/javascript" src="static/libs/jquery.min.js"></script>
    <script type="text/javascript" src="static/libs/layer/layer.js"></script>
    <script type="text/javascript" src="static/admin/js/jquery.utils.min.js"></script>
</head>
<body>
<div class="bg"></div>
<div class="gyl">#(appName)<div class="gy2"></div></div>
<form class="bgForm">
    <div class="wel">用户登录</div>
    <div class="user">
        <div class="label" style="">用户名</div>
        <input type="text" name="loginName" value="" autocomplete="off"/>
    </div>
    <div class="password">
        <div class="label">密&nbsp;&nbsp;&nbsp;码</div>
        <input type="password" name="loginPassword" value="" autocomplete="off"/>
    </div>
    <div class="rem">
        <label>
            <input type="checkbox" name=""/>
            <div id="reb">记住密码</div>
        </label>
    </div>
    <div class="fg">
        <div style="font-size: 11px;margin-top: 11px;">
            <a style="font-size: 11px;" href="javascript:;">忘记密码？</a>
        </div>
    </div>
    <input class="btn" type="button" name="登录" value="登录"/>
</form>

<script type="text/javascript">
	#if(code == -1002){ top.window.location.href = '#(url)'} #end

	$(function(){
		$('.btn').on('click', function(){
			doLogin();
		});
		$('form').on('keydown', function(e){
			if(e.keyCode == 13){
				doLogin();
			}
		})
	})
	
	/** 对输入的数据进行校验， */
	function validate(data){
		if(!data.loginName){
			layer.msg('登陆账号不能为空')
			return false;
		}
		if(!data.loginPassword){
			layer.msg('登陆密码不能为空');
			return false;
		}
		return true;
	}
	
	/** 执行登陆的方法 */
	function doLogin(){
		var data = $('form').toJSON();
		var valid = validate(data);
		if(valid){
			var index = layer.load(1, {
				 shade: [0.1,'#fff']
			});
			$.post('admin/validLogin', data, function(res){
				console.log(res)
				if(res.succeed){
					layer.close(index);
					layer.msg('登陆成功,请稍后...',{time : 1500}, function(){
						window.location.href = res.data;
					})
				} else {
					layer.close(index);
					layer.msg(res.message);
				}
			}, 'json').error(function(msg){
				layer.msg('网络错误', function(){
					layer.close(index)
				})
			})
		}
	}
	
</script>
</body>
</html>
